﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using QuanLyKhachSan.BusinessLogic;
using QuanLyKhachSan.BusinessObject;
using QuanLyKhachSan.DataAccess;
namespace QuanLyKhachSan
{
    public partial class frmChiTietDV : Form
    {
        private ChiTietDVBL ctdvBL = new ChiTietDVBL();
        private DichVuBL dvBL = new DichVuBL();
        private DichVuBO dvBO = new DichVuBO();
        private PhieuThuePhongBL ptpBL = new PhieuThuePhongBL();
        private ChiTietDVBO ctdvBO = new ChiTietDVBO();
        private string maDichVu;
        string chitietdv = null;
        public frmChiTietDV()
        {
            InitializeComponent();
        }

        private void frmChiTietDV_Load(object sender, EventArgs e)
        {
            //load combobox mã dịch vụ
           

            colMaDichVu.DataSource = dvBL.LayDSDichVu();
            colMaDichVu.DisplayMember = "TenDichVu";
            colMaDichVu.ValueMember = "MaDichVu";


            colMaThuePhong.DataSource = ptpBL.LayDSThuePhong();
            colMaThuePhong.DisplayMember = "MaPhong";
            colMaThuePhong.ValueMember = "MaThuePhong";

            dgvwChiTietDV.DataSource = ctdvBL.LayDSChiTietDV();
        }

        private void dgvwChiTietDV_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            int dong = e.RowIndex;
           // txtSTT.Text = dgvwChiTietDV.Rows[dong].Cells["STT"].Value.ToString();
            ctdvBO.MaChiTietDV = dgvwChiTietDV.Rows[dong].Cells["MaChiTietDV"].Value.ToString();
            ctdvBO.MaDichVu = dgvwChiTietDV.Rows[dong].Cells["colMaDichVu"].Value.ToString();
            maDichVu = dgvwChiTietDV.Rows[dong].Cells["colMaDichVu"].Value.ToString();
            ctdvBO.NgaySuDung = Convert.ToDateTime(dgvwChiTietDV.Rows[dong].Cells["NgaySuDung"].Value.ToString());
            ctdvBO.MaThuePhong = dgvwChiTietDV.Rows[dong].Cells["colMaThuePhong"].Value.ToString();
            ctdvBO.SoLuong = int.Parse(dgvwChiTietDV.Rows[dong].Cells["SoLuong"].Value.ToString());
        }

        //xóa trắng các textbox

        private void LayDuLieu(ChiTietDVBO CTDV)
        {
            this.chitietdv = CTDV.MaDichVu;
            if (!chitietdv.Equals(""))
            {
                dgvwChiTietDV.DataSource = ctdvBL.LayDSChiTietDV();
            }
        }
       
     



      



        private void btnThem_Click_1(object sender, EventArgs e)
        {
            frmAddChiTietDV factdv = new frmAddChiTietDV();
            factdv.NextID();
            factdv.DuLieu = new frmAddChiTietDV.DuLieuTruyenVe(LayDuLieu);
            factdv.Show();
        }

        private void btnSua_Click_1(object sender, EventArgs e)
        {
            frmAddChiTietDV factdv = new frmAddChiTietDV();
            factdv.Load_Edit(ctdvBO);
            factdv.DuLieu = new frmAddChiTietDV.DuLieuTruyenVe(LayDuLieu);
            factdv.Show();
        }

        private void btnXoa_Click_1(object sender, EventArgs e)
        {
            if (ctdvBO.MaChiTietDV == "")
                MessageBox.Show("Chọn mã nhân viên", "Chương trình thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
            {
                if (MessageBox.Show("Bạn có chắc muốn xóa hay không", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    ctdvBL.Delete(ctdvBO.MaChiTietDV);
                    frmChiTietDV_Load(sender, e);
                }
            }
        }

        private void btnThoat_Click_1(object sender, EventArgs e)
        {
            bool kq = (MessageBox.Show("Bạn có chắc chắn muốn thoát không ?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes);
            if (kq == true)
            {
                this.Close();
            }
        }

        private void txtTimKiem_KeyUp(object sender, KeyEventArgs e)
        {
            dgvwChiTietDV.DataSource = ctdvBL.TimKiemChiTietDV(txtTimKiem.Text);
        }


    }
}
